package com.mall.coupon.server.controller;

import com.mall.common.core.domain.Result;
import com.mall.common.core.web.controller.BaseController;
import com.mall.coupon.common.domain.CmsCoupon;
import com.mall.coupon.server.service.CmsCouponService;

import com.mall.product.common.domain.PmsSkuInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.mall.common.core.utils.PageUtils.startPage;

@RestController
@RequestMapping("coupon")
public class CmsCouponController extends BaseController {
    @Autowired
    private CmsCouponService cmsCouponService;

    /**
     * 商家查询优惠券列表
     */
    @GetMapping("/list")
    public Result list(CmsCoupon cmsCoupon)
    {
        startPage();
        List<CmsCoupon> list = cmsCouponService.selectCmsCouponList(cmsCoupon);
        return getDataTable(list);
    }




    /**
     * 删除优惠券信息
     */
    @DeleteMapping("/delete/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        cmsCouponService.deleteCmsCouponByIds(ids);
        return Result.success(null,"操作成功");
    }


    /**
     * 修改优惠券状态为失效
     * @param id
     * @return
     */
    @PutMapping("/updateCmsCoupon/{id}")
    public Result updateCmsCoupon(@PathVariable Long id)
    {
        cmsCouponService.updateCmsCoupon(id);
        return Result.success(null,"操作成功");
    }


    /**
     * 添加优惠券
     * @param cmsCoupon
     * @return
     */
    @PostMapping("/insertCmsCoupon")
    public Result insertCmsCoupon(@RequestBody CmsCoupon cmsCoupon)
    {
        cmsCouponService.insertCmsCoupon(cmsCoupon);
        return Result.success(null,"操作成功");
    }




}
